package day0308;

import java.util.*;

public class MyArrayList implements List {

    private Object[] objs;

    private int size;

    private static final int DEFAULT_LENGTH = 10;

    public MyArrayList() {
        objs = new Object[DEFAULT_LENGTH];
    }

    public MyArrayList(int length) {
        if (length < 0) {
            throw new IndexOutOfBoundsException("List 大小不能为负数：" + length);
        }
        objs = new Object[length];
    }

    @Override
    public int size() {
        return this.size;
    }

    @Override
    public boolean isEmpty() {
        return this.size == 0;
    }

    @Override
    public boolean contains(Object o) {
        return false;
    }

    @Override
    public Iterator iterator() {
        return null;
    }

    @Override
    public Object[] toArray() {
        return new Object[0];
    }

    @Override
    public boolean add(Object o) {
        if ( size == objs.length ){
            grow();
        }
        objs[size ++] = o;
        return true;
    }

    private void grow() {
        System.out.println("扩容");
        Object[] objects = new Object[objs.length + objs.length / 2];
        System.arraycopy(objs, 0, objects, 0, size);
        objs = objects;
//        objs = Arrays.copyOf(objs, objs.length + objs.length / 2);
    }

    @Override
    public boolean remove(Object o) {
        return false;
    }

    @Override
    public boolean addAll(Collection c) {
        return false;
    }

    @Override
    public boolean addAll(int index, Collection c) {
        return false;
    }

    @Override
    public void clear() {

    }

    @Override
    public Object get(int index) {
        return null;
    }

    @Override
    public Object set(int index, Object element) {
        return null;
    }

    @Override
    public void add(int index, Object element) {

    }

    @Override
    public Object remove(int index) {
        return null;
    }

    @Override
    public int indexOf(Object o) {
        return 0;
    }

    @Override
    public int lastIndexOf(Object o) {
        return 0;
    }

    @Override
    public ListIterator listIterator() {
        return null;
    }

    @Override
    public ListIterator listIterator(int index) {
        return null;
    }

    @Override
    public List subList(int fromIndex, int toIndex) {
        return null;
    }

    @Override
    public boolean retainAll(Collection c) {
        return false;
    }

    @Override
    public boolean removeAll(Collection c) {
        return false;
    }

    @Override
    public boolean containsAll(Collection c) {
        return false;
    }

    @Override
    public Object[] toArray(Object[] a) {
        return new Object[0];
    }

}
